﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic;
using SubSonicResearch;


namespace OrmSmackdown.SubSonic
{
    public class Crud : ICrud
    {
        public int Create(string firstName, string lastName, string email)
        {
            var user1 = new SubSonicResearch.Person { FirstName = firstName, LastName = lastName, Email = email, UserType = "CN" };
            user1.Save();

            return user1.PersonId;
        }

        public IPerson Read(int id)
        {
            return Person.FetchByID(id) as IPerson;
        }

        public void Update(int id, string firstName, string lastName, string email)
        {
            var person = Person.FetchByID(id);
            person.FirstName = firstName;
            person.LastName = lastName;
            person.Email = email;
            person.Save();
        }

        public void Delete(int id)
        {
            Person.Delete(id);
        }

        public void Dispose()
        {
            
        }
    }
}
